<template>
  <div>
    <FormPanel ref="formPanel" :list="form" :cols="4" :isSubmitBtn="false" @formChange="getPartOrderInfoClick" />
    <div style="text-align: center;">
      <el-button type="primary" @click="FormPanelSeacher">查询</el-button>
      <el-button @click="FormPanelreset">重置</el-button>
    </div>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      columnsRef="partPartPurchasePurchaseOrderCheckIndex"
      :isSelectColumn="false"
      :datakey="'rows'"
      :onEnterEvent="selectDetailed"
      :onColumnsChange="columns => (this.columns = columns)"
    />

    <BaseDialog :visible="website" title="网点查询" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <websiteModel :rowData="websiteCode" @saveDialog="saveDialog" @closeDialog="website = false" />
    </BaseDialog>

    <BaseDialog :visible="purchaseOrderDetile" title="到货确认" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <purchaseOrderDetile :id="id" @saveDialog="purchaseSave" @close="purchaseOrderDetile = false" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getPartOrderInfo } from '@/api/part/partPurchase/purchaseOrderCheck';
import websiteModel from './websiteModel';
import purchaseOrderDetile from './purchaseOrderDetile';

export default {
  name: 'purchaseOrderCheck',
  components: {
    websiteModel,
    purchaseOrderDetile
  },
  mixins: [dictionary],
  data() {
    return {
      form: this.createForm(),
      BaseTable: '',
      id: '',
      purchaseOrderDetile: false,
      websiteCode: '',
      website: false,
      columns: this.createTableColumns(),
      fetchApi: getPartOrderInfo,
      fetchParams: { xhrAbort: true }
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createForm() {
      return [
        {
          type: 'SELECT',
          label: '销售域',
          fieldName: 'salesDomainCode',
          itemList: this.createDictList('8059')
        },
        {
          type: 'SELECT',
          label: '到货状态',
          fieldName: 'orderStatus',
          itemList: this.createDictList('8059')
        },
        {
          type: 'SELECT',
          label: '单据类型',
          fieldName: 'businessTypeCode',
          itemList: this.createDictList('8059')
        },
        {
          type: 'INPUT',
          label: '网点',
          fieldName: 'websiteName',
          unitRender: () => {
            return <el-button icon="el-icon-search" onClick={this.websiteClick} />;
          }
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '单据编号',
          dataIndex: 'orderNo',
          render: props => {
            return <span>{props.row.orderNo}</span>;
          }
        },
        {
          title: '业务类型',
          dataIndex: 'businessTyped',
          render: props => {
            return <span>{props.row.businessTyped}</span>;
          }
        },
        {
          title: '网点名称',
          dataIndex: 'websiteName',
          render: props => {
            return <span>{props.row.websiteName}</span>;
          }
        },
        {
          title: '网点代码',
          dataIndex: 'websiteCode',
          render: props => {
            return <span>{props.row.websiteCode}</span>;
          }
        },
        {
          title: '仓库名称',
          dataIndex: 'storageName',
          hidden: true,
          render: props => {
            return <span>{props.row.storageName}</span>;
          }
        },
        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          hidden: true,
          render: props => {
            return <span>{props.row.storageCode}</span>;
          }
        },
        {
          title: '状态',
          dataIndex: 'orderStatus',
          render: props => {
            return <span>{props.row.orderStatus}</span>;
          }
        },
        {
          title: '提货方式',
          dataIndex: 'transportWayName',
          render: props => {
            return <span>{props.row.transportWayName}</span>;
            1;
          }
        },
        {
          title: '收货人',
          dataIndex: 'consignee',
          render: props => {
            return <span>{props.row.consignee}</span>;
          }
        },
        {
          title: '价格策略',
          dataIndex: 'priceStrategyName',
          render: props => {
            return <span>{props.row.priceStrategyName}</span>;
            1;
          }
        },
        {
          title: '销售域',
          dataIndex: 'salesDmainName',
          render: props => {
            return <span>{props.row.salesDmainName}</span>;
          }
        },
        {
          title: '单据类型',
          dataIndex: 'orderTypeName',
          render: props => {
            return <span>{props.row.orderTypeName}</span>;
          }
        },
        {
          title: '信用账户',
          dataIndex: 'creditAccountName',
          render: props => {
            return <span>{props.row.creditAccountName}</span>;
          }
        },
        {
          title: '税率',
          dataIndex: 'tax',
          render: props => {
            return <span>{props.row.tax}</span>;
          }
        },
        {
          title: '提交日期',
          dataIndex: 'reportDate',
          filterType: 'date-range',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          render: props => {
            return <span>{props.row.reportDate}</span>;
          }
        },
        {
          title: '联系人',
          dataIndex: 'contact',
          render: props => {
            return <span>{props.row.contact}</span>;
          }
        },
        {
          title: '电话',
          dataIndex: 'phone',
          render: props => {
            return <span>{props.row.phone}</span>;
          }
        },
        {
          title: '手机',
          dataIndex: 'mobilePhone',
          render: props => {
            return <span>{props.row.mobilePhone}</span>;
          }
        },
        {
          title: '操作员',
          dataIndex: 'operaorName',
          render: props => {
            return <span>{props.row.operaorName}</span>;
          }
        },
        {
          title: '操作日期',
          dataIndex: 'createdAt',
          filterType: 'date-range',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          render: props => {
            return <span>{props.row.createdAt}</span>;
          }
        },
        {
          title: '货币名称',
          dataIndex: '1',
          initialValue: '人民币'
        },
        {
          title: '地址',
          dataIndex: 'address',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.address}</span>;
          }
        }
      ];
    },
    saveDialog(val) {
      this.form.find(x => x.fieldName === 'websiteName').initialValue = val.businessNetworkName;
      this.websiteCode = val.businessNetworkCode;
      this.website = false;
    },
    websiteClick() {
      this.websiteCode = this.form.find(x => x.fieldName === 'websiteName').initialValue;
      this.website = true;
    },
    purchaseSave(val) {},
    selectDetailed(val) {
      console.log(val);
      this.id = val.id;
      this.purchaseOrderDetile = true;
    },
    FormPanelreset() {
      this.$refs.formPanel.RESET_FORM();
    },
    FormPanelSeacher(val) {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    getPartOrderInfoClick(val) {
      console.log(val, 'valllll');
      // let obj = {
      //   websiteName: '111'
      // }
      // console.log(obj,'obj')
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  }
};
</script>
